package com.ruoyi.project.business.salaryoptions.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.salaryoptions.entity.SalaryOptions;
import com.ruoyi.project.business.salaryoptions.request.ListSalaryOptionsRequest;
import com.ruoyi.project.business.salaryoptions.request.AddSalaryOptionsRequest;
import com.ruoyi.project.business.salaryoptions.response.SalaryOptionsResponse;
import com.ruoyi.project.business.salaryoptions.service.ISalaryOptionsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 薪资计算项Controller
 * 
 * @author ${author}
 * @date 2024-02-21
 */
@RestController
@RequestMapping("/business/salaryoptions")
public class SalaryOptionsController extends BaseController {
    @Autowired
    private ISalaryOptionsService salaryOptionsService;

    /**
     * 查询薪资计算项列表
     */
    @PreAuthorize("@ss.hasPermi('business:salaryoptions:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListSalaryOptionsRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<SalaryOptionsResponse> list = salaryOptionsService.selectSalaryOptionsList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出薪资计算项列表
     */
    @PreAuthorize("@ss.hasPermi('business:salaryoptions:export')")
    @Log(title = "薪资计算项", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListSalaryOptionsRequest request) {
        Long tenantId = getTenantId();
        List<SalaryOptionsResponse> list = salaryOptionsService.selectSalaryOptionsList(request, tenantId);
        ExcelUtil<SalaryOptionsResponse> util = new ExcelUtil<>(SalaryOptionsResponse.class);
        return util.exportExcel(list, "salaryoptions");
    }

    /**
     * 获取薪资计算项详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:salaryoptions:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(salaryOptionsService.selectSalaryOptionsById(id));
    }

    /**
     * 新增薪资计算项
     */
    @PreAuthorize("@ss.hasPermi('business:salaryoptions:add')")
    @Log(title = "薪资计算项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddSalaryOptionsRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(salaryOptionsService.insertSalaryOptions(request, operatorId, tenantId));
    }

    /**
     * 修改薪资计算项
     */
    @PreAuthorize("@ss.hasPermi('business:salaryoptions:edit')")
    @Log(title = "薪资计算项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SalaryOptions salaryOptions) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(salaryOptionsService.updateSalaryOptions(salaryOptions, operatorId, tenantId));
    }

    /**
     * 删除薪资计算项
     */
    @PreAuthorize("@ss.hasPermi('business:salaryoptions:remove')")
    @Log(title = "薪资计算项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(salaryOptionsService.deleteSalaryOptionsByIds(ids, operatorId, tenantId));
    }
}
